"""
A class to exercise the JT core functions.
"""
import itk
import vtk
import JT
import Calibration
from numpy import array

def Test_JTVolumeRendering():
    """
    Test the volume rendering implemented in JT
    """
    inputFixedFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/fluoro/ushortim080-LAT.mha'
    inputVolFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.mha'
    staFile = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.sta'
    calFileLat = 'C:/Users/bryan/bryan-code/trunk/TestData/ext_cal1.txt'

#===============================================================================
#    
#    Generate Lateral Projection
#    
#===============================================================================
    xraycamLat = JT.XRayCamera()
    drrLat = JT.DRR()
    calLat = Calibration.ExternalCalibration()


    calLat.LoadConsolidatedCalibration(calFileLat)
    calLat.LoadStaFile(staFile)
    drrLat.SetXRayCamera(xraycamLat)
    drrLat.SetVolumeFilename(inputVolFileName)

#===============================================================================
#    
#    Automatic calibration
#    
#===============================================================================
    xraycamLat.SetExternalCalibration(calLat)

    vtkMatrixLAT = calLat.ConvertNumpyToVTKArray(calLat._VolumeT)
    drrLat.SetVolumeUserMatrix(vtkMatrixLAT)
    drrLat.SetBlackOnWhiteImage()
    
    ic = JT.ImageCanvas()
    ic.SetFileName(inputFixedFileName)
    drrLat.SetBackgroundImage(ic._vtkImage)
    
    drrLat.Render()
    
    #Debugging, save the final generated image
    drrLat.SaveGeneratedImage('C:/Users/bryan/bryan-code/trunk/Images/CurrentDRR.mhd')


if __name__ == "__main__":
    Test_JTVolumeRendering()